package jude.java.money.batch.task.expand;

import java.util.ArrayList;
import java.util.List;

import jude.java.money.batch.Definition;

public class ResultFilter {
	
	private List<String> ignores;
	private List<String> prefixs;
	
	public ResultFilter() {
	}

	private ResultFilter(String... strings) {
		ignores = new ArrayList<String>();
		prefixs = new ArrayList<String>();
		ignores.add(Definition.SUCCESS);
		ignores.add(Definition.IGNORE);
		for (int i = 0; i < strings.length; i++) {
			String str = strings[i];
			if (str.charAt(0) == '@')
				prefixs.add(str.substring(1));
			else
				ignores.add(str);
		}
	}
	
	public static ResultFilter get(String... filters) {
		return new ResultFilter(filters);
	}
	
	public boolean show(String domain, String result) {
		if (ignores != null)
			for (String ignore : ignores) {
				if (ignore.equals(result))
					return false;
			}
		if (prefixs != null)
			for (String prefix : prefixs) {
				if (result.startsWith(prefix))
					return false;
			}
		return true;
	}
}
